import Store from '@/store'
import GameLine from './gameLine'
import Mode1 from './mode/mode1'
import Mode2 from './mode/mode2'
import MouseEvent from './mouseEvent'
import ThreeManager from './threeManager'
import HandleBtn  from './handleBtn'
export default class Sweeper {
  constructor(_vue) {
    this._vue = _vue
    this.initData()
  }
  initData() {
    // console.log(Store)
    this.themeColor = { ...Store.getters.getByState('themeColor') }
    this.difficulty = { ...Store.getters.getByState('difficulty') }
    this.settings = Store.getters.getByState('settings') //只读访问
    this.musicCtrl = Store.getters.getByState('musicCtrl')
    this.user = Store.getters.getByState('user')
    this.counter = {
      countNum: this.difficulty.mineNum,
      mineNum: this.difficulty.mineNum,
      knowNum: 0
    }
    //状态管理
    this.isDrag = false
    this.handleFlag = 'dig'
    this.hiddenList = []
    this.numData = undefined

    this.gameLine = new GameLine(this)
    this.handleBtn = new HandleBtn(this)
    //模式识别
    if (this.difficulty.mode == 1) {
      this.mode = new Mode1(this)
    } else if (this.difficulty.mode == 2) {
      this.mode = new Mode2(this)
    } else {
      throw new Error('mode id is error:' + this.difficulty.mode)
    }
  }
  afterMounted() {
    //会对dom进行操作
    this.threeManager = new ThreeManager(this)
    this.mouseEvent = new MouseEvent(this)
  }
  dispose() {
    this.threeManager.dispose()
  }
  refreshGame(){
    
    this.counter.countNum = this.difficulty.mineNum
    this.counter.mineNum = this.difficulty.mineNum
    this.counter.knowNum = 0
    this.isDrag = false
    this.handleFlag = 'dig'
    this.hiddenList = []
    this.numData = undefined
    this.gameLine.init()
    this.handleBtn.init()
    //mode不需要重置
    this.threeManager.refresh()
    this.mouseEvent.init()
  }
}
/**
 *
 * 本实例中创建的对象：
 * gameLine
 * threeManager
 *
 * meshCover在threeManager创建
 * musicCtrl在store中获取
 *
 */
